package com.yunc.modules.cms.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yunc.base.controller.CommonController;
import com.yunc.common.utils.R;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yunc.modules.cms.entity.QuestionSubjectSelect;
import com.yunc.modules.cms.service.IQuestionSubjectSelectService;

/**
 * 问卷题目选项表 前端控制器
 *
 * @author concong tao
 * @since 2019-01-31
 */
@RestController
@RequestMapping("/cms/questionSubjectSelect")
public class QuestionSubjectSelectController extends CommonController {

    @Autowired
    private IQuestionSubjectSelectService questionSubjectSelectService;

    @GetMapping("/page")
    public R page(Page<QuestionSubjectSelect> page, QuestionSubjectSelect questionSubjectSelect){
        questionSubjectSelectService.page(page, new QueryWrapper<>(questionSubjectSelect));
        return R.ok().put("data", page.getRecords()).put("count", page.getTotal());
    }

    @GetMapping("/info/{id}")
    public R info(@PathVariable Long id){
        QuestionSubjectSelect questionSubjectSelect = questionSubjectSelectService.getById(id);
        return R.ok().put("questionSubjectSelect", questionSubjectSelect);
    }

    @PostMapping("/save")
    public R save(@RequestBody QuestionSubjectSelect questionSubjectSelect){
        boolean flag = questionSubjectSelectService.save(questionSubjectSelect);
        if (flag) {
            return R.ok();
        }
        return R.error();
    }

    @PutMapping(value = "/update")
    public R update(@RequestBody QuestionSubjectSelect questionSubjectSelect){
        boolean flag = questionSubjectSelectService.updateById(questionSubjectSelect);
        if (flag) {
            return R.ok();
        }
        return R.error();
    }

    @DeleteMapping("/delete/{id}")
    public R delete(@PathVariable Long id){
        boolean flag = questionSubjectSelectService.removeById(id);
        if (flag) {
            return R.ok();
        }
        return R.error();
    }
}
